<?php
/**
 * Lấy danh sách user trong DB
 * @return type 
 */
function get_list_user()
{
    mysqli_query(getDB(), "SET NAMES UTF8");
    $result = mysqli_query(getDB(), "SELECT * FROM accounts");
    $list = array();
    if(mysqli_num_rows($result) > 0)
    {
        while($row = mysqli_fetch_assoc($result))
        {
            $list[] = $row;
        }
    }
    return $list;
}
/**
 * Lấy thông tin về user theo ID
 * @param type $id
 * @return array()
 */
function get_user($id)
{
    mysqli_query(getDB(), "SET NAMES UTF8");
    $result = mysqli_query(getDB(), "SELECT `accounts`.`UserId`, Fullname, Email,Phone, Sex, Dob, Career, Address, Avatar 
                                    FROM accounts JOIN profiles ON  `profiles`.`UserId` = `accounts`.`UserId`
                                    WHERE `accounts`.`UserId` = '{$id}' LIMIT 1");
    if(($result !== false) and (mysqli_num_rows($result) > 0))
    {
        while($row = mysqli_fetch_assoc($result))
        {
            return $row;
        }
    }
}
/**
 *  
 */
function update_user_status($uid, $status)
{
    if(!in_array($status, array('0','1'))) return false;
    return mysqli_query(getDB(), "UPDATE `accounts` SET `Active` = '{$status}' WHERE `UserId` = '{$uid}';");
}
?>
